package ro.cdv.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import ro.cdv.service.ProductService;

@Controller
public class ProductController {

	private ProductService productService;

	@Autowired
	public ProductController(ProductService productService) {
		this.productService = productService;
	}

	@RequestMapping("/")
	public String list(final ModelMap model) {
		model.put("products", productService.getProducts());
		return "list";
	}

	@RequestMapping("/product/{id}")
	public String detail(@PathVariable(value = "id") Integer productId,
			ModelMap model) {
		model.put("product", productService.getProductById(productId));
		return "details";
	}
}
